package com.yz.delayqueue;

import java.text.DateFormat;
import java.util.Date;
import java.util.concurrent.DelayQueue;

/**
 * @author yuanzheng
 * @date 2020/11/16-17:35
 */
public class DelayMessageTest {
    public static void main(String[] args) throws InterruptedException {
        DelayQueue<DelayMessage> delayMessages = new DelayQueue<>();
        delayMessages.offer(new DelayMessage(1, "消息体1", 1000L));
        delayMessages.offer(new DelayMessage(2, "消息体2", 3000L));
        System.out.println("开始执行时间：" + DateFormat.getDateTimeInstance().format(new Date()));
        while (!delayMessages.isEmpty()) {
            System.out.println(delayMessages.take());
        }
        System.out.println("结束执行时间：" + DateFormat.getDateTimeInstance().format(new Date()));
    }
}
